define(function (require, exports, module) {

    var layout = require("modules/layout/index.js");
    var sideTree = require("modules/side-tree/index.js");
    var multiPage = require("modules/multi-page/index.js");

    var _ = require("http://localhost:8180//git-my/vue-ladder/src/lib/lodash.js");

    window.vueApp = new Vue({
        el: '#app',
        data: {
            innerPage: {
                pages: [{
                    menuName: '组件列表',
                    url: '01-componentList.html',
                    active: true
                }],
                hasTop: true,
                //hasTitle: 直接取hastop的反向
            },
            isCollapse: true,
            tree: [{
                menuName: '组表管理',
                level: 1,
                // iconCls: 'fa-bar-chart-o',
                iconCls: 'fa-cube',
                collapsed: false,
                active: true,
                children: [{
                    menuName: '组件列表',
                    level: 2,
                    active: true,
                    url: '01-componentList.html'

                }]
            }, {
                menuName: '服务管理',
                level: 2,
                // iconCls: 'fa-bar-chart-o',
                iconCls: 'fa-diamond',
                collapsed: true,
                active: false,
                children: [{
                    menuName: '服务列表',
                    level: 2,
                    active: false,
                    url: '07-apiList.html'

                }]
            }, {
                menuName: '路由负载',
                level: 1,
                collapsed: true,
                iconCls: 'fa-table',
                active: false,
                children: [{
                    level: 2,
                    url: '03-supplierList.html',
                    menuName: '供应商列表',
                    active: false

                }]
            }, {
                menuName: '数据库管理',
                level: 1,
                collapsed: true,
                iconCls: 'fa-database',
                active: false,
                children: [{
                    level: 2,
                    url: '06-dbTableList.html',
                    menuName: '数据库表列表',
                    active: false
                }]
            }],
            defaultProps: {
                children: 'children',
                label: 'label'
            }
        },
        methods: {

            handleClick(row) {
                row.edit = !row.edit;
            }
        },
        mounted: function () {


            $(window).bind("load resize", this.myResize);
            setTimeout(this.myResize, 0);



        },
        events: {

        },
        methods: {
            innerPageAdd: function (node) {

                if (!this.innerPage.hasTop) {
                    this.innerPage.pages = [];
                    node["active"] = true;
                    this.innerPage.pages.push(node);
                }

                var hasIn = false;
                _.forEach(this.innerPage.pages, function (page) {
                    if (page.menuName == node.menuName) {
                        page.active = true;
                        hasIn = true;
                    } else {
                        page.active = false;
                    }

                });


                if (!hasIn) {
                    node["active"] = true;
                    this.innerPage.pages.push(node);
                }


            },
            innerPageMove: function (node) {
                var hasIn = false;
                this.innerPage.pages = _.remove(this.innerPage.pages, function (page) {
                    return page.menuName != node.menuName;
                });

                if (this.innerPage.pages.length > 0) {
                    this.innerPage.pages[this.innerPage.pages.length - 1].active = true;
                }



            },
            myResize: function () {
                var outerWidth = $(window).width();
                var outerHeight = $(window).height();
                $("#app").css({
                    height: outerHeight + 'px'
                });
            },
            toggleHasTop: function (to) {
                if (to == undefined) {
                    this.innerPage.hasTop = !this.innerPage.hasTop;
                } else {
                    this.innerPage.hasTop = to;
                }
            }
        }

    });

});